const { Nuxt, Builder, loadNuxt } = require("nuxt");
const app = require("express")();
const port = process.env.PORT || 3000;

// 传入配置初始化 Nuxt.js 实例
const config = require("../../nuxt.config.js");
const nuxt = new Nuxt(config);
app.use(nuxt.render);

// 在开发模式下进行编译
if (config.env) {
  new Builder(nuxt).build();
}

app.get("/*", (req, res) => {
  console.log("req", req, res);
  nuxt.render(req, res);
});
// 监听指定端口
app.listen(port, "127.0.0.1");
console.log("我搭建的服务器运行于 localhost:" + port);
